package com.ordering.action.user.register;

import java.security.NoSuchAlgorithmException;

import com.ordering.action.BaseAction;
import com.ordering.entity.User;
import com.ordering.service.register.RegisterService;
import com.ordering.service.register.impl.RegisterServiceImpl;
import com.ordering.util.DateAndTime;
import com.ordering.util.MD5;
import com.ordering.util.VerifyUtil;

public class RegisterAction extends BaseAction
{
    //输入
    private String msisdn;
    private String name;
    private String password;
    private String imageCode;
    //输出
    private boolean status;
    private String errorMsg;
    private User user;
    RegisterService registerService = new RegisterServiceImpl();
     
    public String execute() {
        User po = new User();
        try
        {
            if(!VerifyUtil.isMsisdn(msisdn)){
                status = false;
                
            }
            String time = DateAndTime.getCurrentTime();
            
            po.setMsisdn(msisdn);
            po.setName(name);
            po.setPassword(MD5.crypt(password));
            po.setRegisterTime(time);
            po.setLastModifyTime(time);
            po.setAddr("add");
            po.setBirthday("2014");
            po.setEmail("ss");
            po.setSex(1);
            po.setStatus(1);
            registerService.register(po);
        }
        catch (NoSuchAlgorithmException e)
        {
            e.printStackTrace();
            
        }
        user = po;
        return SUCCESS;
    }

    public String getMsisdn()
    {
        return msisdn;
    }

    public void setMsisdn(String msisdn)
    {
        this.msisdn = msisdn;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getImageCode()
    {
        return imageCode;
    }

    public void setImageCode(String imageCode)
    {
        this.imageCode = imageCode;
    }

    public boolean isStatus()
    {
        return status;
    }

    public void setStatus(boolean status)
    {
        this.status = status;
    }

    public String getErrorMsg()
    {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg)
    {
        this.errorMsg = errorMsg;
    }

    public User getUser()
    {
        return user;
    }

    public void setUser(User user)
    {
        this.user = user;
    }
}
